<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     default_default
 */
?>
<?php
/**
 * @see Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer
 * @var Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer $this 
 */
?>

<?php $_item = $this->getItem() ?>
<?php $items = $this->getChilds($_item); ?>
<?php $_count = count ($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

<?php if($this->getOrderOptions() || $_item->getDescription()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif ?>

<?php foreach ($items as $_item): ?>
    <?php $this->setPriceDataObject($_item) ?>
    <?php if ($_item->getOrderItem()->getParentItem()): ?>
        <?php $attributes = $this->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td><div class="option-label"><?php echo $this->escapeHtml($attributes['option_label']); ?></div></td>
            <td>&nbsp;</td>
            <td class="last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif ?>
    <?php endif ?>
    <tr class="<?php echo (++$_index==$_count && !$_showlastRow)?'border':'' ?>">
        <?php if (!$_item->getOrderItem()->getParentItem()): ?>
        <td><h5 class="title"><?php echo $this->escapeHtml($_item->getName()) ?></h5>
            <div>
                <strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong>
                <?php echo implode('<br />', Mage::helper('catalog')->splitSku($this->escapeHtml($_item->getSku()))); ?>
            </div>
        </td>
        <?php else: ?>
        <td><div class="option-value"><?php echo $this->getValueHtml($_item)?></div></td>
        <?php endif ?>
        <td>
            <?php if ($this->isShipmentSeparately($_item)): ?>
                <?php echo $this->getColumnHtml($_item, 'qty') ?>
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
        <td class="last">
            <?php if ($this->isShipmentSeparately($_item)): ?>
                <input type="text" class="input-text" name="shipment[items][<?php echo $_item->getOrderItemId() ?>]" value="<?php echo $_item->getQty()*1 ?>" />
            <?php else: ?>
                &nbsp;
            <?php endif ?>
        </td>
    </tr>
<?php endforeach ?>
<?php if($_showlastRow): ?>
    <tr class="border">
        <td>
            <?php if ($this->getOrderOptions($_item->getOrderItem())): ?>
                <dl class="item-options">
                <?php foreach ($this->getOrderOptions($_item->getOrderItem()) as $option): ?>
                    <dt><?php echo $this->escapeHtml($option['label']) ?></dt>
                    <dd>
                    <?php if (isset($option['custom_view']) && $option['custom_view']): ?>
                        <?php echo $option['value'];?>
                    <?php else: ?>
                        <?php echo Mage::helper('core/string')->truncate($option['value'], 55, '', $_remainder);?>
                        <?php if ($_remainder):?>
                            ... <span id="<?php echo $_id = 'id' . uniqid()?>"><?php echo $_remainder ?></span>
                            <script type="text/javascript">
                            $('<?php echo $_id ?>').hide();
                            $('<?php echo $_id ?>').up().observe('mouseover', function(){$('<?php echo $_id ?>').show();});
                            $('<?php echo $_id ?>').up().observe('mouseout',  function(){$('<?php echo $_id ?>').hide();});
                            </script>
                        <?php endif ?>
                    <?php endif ?>
                    </dd>
                <?php endforeach ?>
                </dl>
                        <?php else: ?>
                &nbsp;
                        <?php endif ?>
            <?php echo $this->escapeHtml($_item->getDescription()) ?>
        </td>
        <td>&nbsp;</td>
        <td class="last">&nbsp;</td>
    </tr>
<?php endif ?>
